package com.asyf.provider.controller;

import com.asyf.provider.service.XaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * XA模式测试：
 * 需要把DataSourceProxyConfig2中的数据源改成XA数据源
 */
@Api(tags = "seata事务XA模式")
@RestController
@RequestMapping(value = "/xa")
public class XaController {

    @Autowired
    private XaService xaService;


    //注意：测试的事务不要使用xa的数据源（可以支持联合主键）
    @ApiOperation(value = "事务测试(oracle+mysql)")
    @RequestMapping(value = "/demo", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "数字除数", name = "a", example = "1")
    })
    public String demo2(int a) {
        return xaService.demo(a);
    }

}
/**
 * 笔记
 * 1注解：@BusinessActionContextParameter
 * 注解标记的参数会在上下文中传播，即能通过BusinessActionContext对象在commit方法及cancel方法中取到该参数值
 */